home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 27 / CU Amiga Magazine's Super CD-ROM 27 (1998)(EMAP Images)(GB)[!][issue 1998-10].iso / CUCD / Programming / THXPlayLib / src / init.asm next >
Encoding:
Assembly Source File  |  1998-05-10  |  4.8 KB  |  186 lines

  1. ;****** thxplay.library/thxInit ******************************************
  2. ;
  3. ;   NAME
  4. ;       thxInit -- initialise player and module.
  5. ;
  6. ;   SYNOPSIS
  7. ;       error = thxInit(module)
  8. ;       D0              A0
  9. ;
  10. ;       ULONG thxInit(APTR);
  11. ;
  12. ;       error := thxInit(module)
  13. ;
  14. ;   FUNCTION
  15. ;       Initialises  the  player (if needed) and initializes the module. You
  16. ;       may  also  call  thxInit(NIL)  to  initialise the player but not the
  17. ;       module.  Does not start to play the module until you call thxPlay().
  18. ;       You  must  call  this each time you want to play a different module.
  19. ;       The allocations made for the player are made only the first time you
  20. ;       call  thxInit(), no matter how many modules you want. If allocations
  21. ;       fail, they will be automatically freed.
  22. ;
  23. ;   INPUTS
  24. ;       module - pointer to a THX module or NIL
  25. ;
  26. ;   RESULT
  27. ;       error - zero means all went OK, any other value means failure.
  28. ;
  29. ;   NOTE
  30. ;       In  the  library  version of this interface, thxInit() and thxFree()
  31. ;       use  a task ownership system - to begin with, nobody 'owns' THX. The
  32. ;       first  task  to  call  thxInit() will then 'own' THX, and successive
  33. ;       calls  to  thxInit()  and thxFree() will only succeed for this task.
  34. ;       When  this  task calls thxFree(), the owner goes back to nobody, and
  35. ;       now other tasks are free to use THX.
  36. ;
  37. ;       This  is the only arbitration used by the interface. All other calls
  38. ;       may  be called from any task at all. Please respect this arbitration
  39. ;       mechanism and avoid calling other THX functions unless thxInit() has
  40. ;       succeeded  for  you. You must call thxFree() from the same task that
  41. ;       called thxInit().
  42. ;
  43. ;   SEE ALSO
  44. ;       thxFree(), thxPlay()
  45. ;
  46. ;****************************************************************************
  47. ;
  48. ;
  49.     cnop    0,4
  50. thxInit
  51.     ifd    STACKARGS
  52.     move.l    4(sp),a0
  53.     endc
  54.  
  55.     movem.l    d2-d7/a2-a6,-(sp)
  56.     lea    mod(pc),a1
  57.     move.l    a0,(a1)            ; store moduleptr
  58.  
  59.     lea    mod_OK(pc),a0
  60.     clr.b    (a0)            ; mod is NOT ok until we say so
  61.     lea    song(pc),a0
  62.     clr.w    (a0)            ; set current subsong to 0
  63.  
  64. ; allocate player memory/allocate channels and such
  65.     move.b    init_OK(pc),d0
  66.     bne.s    .setmod            ; skip if already done
  67.     moveq    #0,d0
  68.     moveq    #0,d1
  69.     sub.l    a0,a0            ; auto-allocate public mem (fast)
  70.     sub.l    a1,a1            ; auto-allocate chip mem
  71.     bsr    THX+thxInitPlayer
  72.     tst.l    d0
  73.     bne    .fail
  74.     lea    init_OK(pc),a0
  75.     st.b    (a0)
  76.  
  77. ; initialise module (must be before initCIA)
  78. .setmod    move.l    mod(pc),d0
  79.     beq.s    .nomod
  80.     move.l    d0,a0
  81.     bsr    THX+thxInitModule
  82.     moveq    #0,d0        ; start with main song
  83.     moveq    #1,d1        ; don't play immediately
  84.     bsr    THX+thxInitSubSong
  85.  
  86.  
  87. ; try to allocate CIA interrupt
  88. .nomod    move.b    cia_OK(pc),d0
  89.     bne.s    .done            ; skip if already installed
  90.     lea    intcode(pc),a0
  91.     moveq    #0,d0
  92.     bsr    THX+thxInitCIA        ; install intcode
  93.     tst.l    d0
  94.     bne.s    .nocia
  95.     lea    cia_OK(pc),a0
  96.     st.b    (a0)
  97.     bra.s    .done
  98.  
  99. ; if CIA allocation failed, try to allocate VERTB interrupt
  100. .nocia    move.b    vb_OK(pc),d0
  101.     bne.s    .done            ; skip is already installed
  102.     move.l    4.w,a6
  103.     lea    int(pc),a1
  104.     moveq    #INTB_VERTB,d0
  105.     jsr    _LVOAddIntServer(a6)    ; install intcode
  106.     lea    vb_OK(pc),a0
  107.     st.b    (a0)
  108.  
  109. .done    move.l    mod(pc),d0    ; if module is not-null, initialise it _again_
  110.     beq.s    .exit        ; this time _after_ interrupt is installed
  111.     move.l    d0,a0
  112.     bsr    THX+thxInitModule
  113.     moveq    #0,d0        ; start with main song
  114.     moveq    #1,d1        ; don't play immediately
  115.     bsr    THX+thxInitSubSong
  116.     bsr    THX+thxStopSong    ; reset timer, audiochannels
  117.     lea    mod_OK(pc),a0
  118.     st.b    (a0)
  119.     moveq    #0,d0
  120.     bra.s    .exit
  121.  
  122. .fail    bsr.s    thxFree            ; on failure, free everything
  123.     moveq    #-1,d0            ; return failure
  124. .exit    movem.l    (sp)+,d2-d7/a2-a6
  125.     rts
  126.  
  127.  
  128.  
  129.  
  130. ;****** thxplay.library/thxFree ******************************************
  131. ;
  132. ;   NAME
  133. ;       thxFree -- free resources held by player.
  134. ;
  135. ;   SYNOPSIS
  136. ;       void thxFree()
  137. ;
  138. ;       void thxFree(void);
  139. ;
  140. ;       thxFree()
  141. ;
  142. ;   FUNCTION
  143. ;       Stops any THX module playing and frees resources used by the player.
  144. ;       You can call this whether thxInit() suceeded or not.
  145. ;
  146. ;   SEE ALSO
  147. ;       thxInit()
  148. ;
  149. ;****************************************************************************
  150. ;
  151. ;
  152.     cnop    0,4
  153. thxFree    movem.l    d2-d7/a2-a6,-(sp)
  154.     bsr    thxStop            ; stop play
  155.  
  156.     move.b    cia_OK(pc),d0
  157.     beq.s    .nocia
  158.     bsr    THX+thxKillCIA        ; remove CIA int if running
  159.     
  160. .nocia    move.b    vb_OK(pc),d0
  161.     beq.s    .novb
  162.     move.l    4.w,a6
  163.     lea    int(pc),a1
  164.     moveq    #INTB_VERTB,d0
  165.     jsr    _LVORemIntServer(a6)    ; remove VB int if running
  166.  
  167. .novb    move.b    init_OK(pc),d0
  168.     beq.s    .noinit
  169.     bsr    THX+thxKillPlayer    ; free player resources
  170.  
  171. .noinit    lea    cia_OK(pc),a2
  172.     clr.l    (a2)            ; clear cia_OK, vb_OK, init_OK & mod_OK
  173.     movem.l    (sp)+,d2-d7/a2-a6
  174.     rts
  175.  
  176.  
  177.  
  178.  
  179. ; VARIABLES
  180. mod    dc.l    0    ; APTR the current module
  181.  
  182. cia_OK    dc.b    0    ; BOOL int routine is CIA, and is init'd and running
  183. vb_OK    dc.b    0    ; BOOL int routine is VBI, and is init'd and running
  184. init_OK    dc.b    0    ; BOOL initialisation (memory, etc) is done
  185. mod_OK    dc.b    0    ; BOOL module is initialised, play can commence
  186.